// Learn TypeScript:
//  - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html

import BaseView from "../base/BaseView";

const {ccclass, property} = cc._decorator;

@ccclass
export default class KLineNodeView extends BaseView {

    @property(cc.Label)
    nameLabel: cc.Label = null;

    @property(cc.Label)
    codeLabel: cc.Label = null;

    @property(cc.Label)
    rateLabel: cc.Label = null;

    @property(cc.Label)
    dateLabel: cc.Label = null;

    @property(cc.Node)
    infoLayer: cc.Node = null;

    onLoad () {

    }

    start () {

    }

    show(params?: any): void {
        super.show(params);
        this.node.active = true;
        this.codeLabel.string = params.ts_code;
        this.nameLabel.string = params.name;
        this.rateLabel.string = params.change;
        this.dateLabel.string = params.date;

        let texts = ['开', '收', '高', '低', '额', '量', '换'];
        let values = [
            params.open, 
            params.close, 
            params.high, 
            params.low, 
            Math.floor(params.amount / 10000) + '万元', 
            Math.floor(params.volume / 10000) + '万手',
            params.turnrate,
        ];
        for (let index = 0; index < texts.length; index++) {
            const title = texts[index];
            const value = values[index];
            let node = this.infoLayer.children[index];
            this.setItem(node, title, value);
        }
        
    }

    setItem(node: cc.Node, title: string, value: string) {
        let titleLabel = node.getChildByName('title').getComponent(cc.Label);
        titleLabel.string = title;
        let valueLabel = node.getChildByName('text').getComponent(cc.Label);
        valueLabel.string = value + '';
    }

    // update (dt) {}
}
